package org.procrastinationapp.web.pages;

import org.apache.wicket.model.LoadableDetachableModel;
import org.procrastinationapp.business.entities.user.User;
import org.procrastinationapp.business.services.aaa.AaaService;

/**
 * A detachable model that can load an User object from persistent store.
 * 
 * @author ivaynberg
 */
public class UserModel extends LoadableDetachableModel {
	private AaaService aaaService;
	private String login;

	public UserModel(AaaService aaaService) {
		this.aaaService = aaaService;
	}

	/**
	 * @param user
	 *            object this model will represent
	 */
	public UserModel(User user, AaaService aaaService) {
		super(user);
		this.login = user.getLogin();
		this.aaaService = aaaService;
	}

	protected Object load() {
		return aaaService.getUser(login);
	}

}
